package arithmetic1.tiantisai;

import java.util.Scanner;

public class Demo56  {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int num = Integer.parseInt(scanner.nextLine());
        String names[]=new String[num];
        int scores[]=new int[num];
        for (int i = 0; i < num; i++) {
            String str = scanner.nextLine();
            String strs[]=str.split("[ ]");
            names[i]=strs[0];
            scores[i]=Integer.parseInt(strs[1]);
        }
        int arr[] = function(scores);
        System.out.println(arr[1]+" "+names[arr[0]]);
    }

    //返回数组里面最接近平均值一半的数的索引,和平均数的一半
    public static int[] function(int scores[]){
        int add=0;
        for(int score:scores){
            add+=score;
        }
        int ave=add/scores.length/2;
        //记录索引
        int index=0;
        //记录差值
        int value=100;
        for(int i=0;i<scores.length;i++){
            if(Math.abs(scores[i]-ave)<value){
                value=Math.abs(scores[i]-ave);
                index=i;
            }
        }
        return new int[]{index,ave};
    }
}
